aboutsummaryrefslogtreecommitdiff
path: root/src/app/(main)/websites/[websiteId]/WebsiteTabs.tsx
blob: ac978a238407fadd3d24f850ccc745c60f7f1f65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Icon, Row, Tab, TabList, Tabs, Text } from '@umami/react-zen';
import { useMessages, useNavigation, useWebsite } from '@/components/hooks';
import { ChartPie, Clock, Eye, User } from '@/components/icons';
import { Lightning } from '@/components/svg';

export function WebsiteTabs() {
  const website = useWebsite();
  const { pathname, renderUrl } = useNavigation();
  const { formatMessage, labels } = useMessages();

  const links = [
    {
      id: 'overview',
      label: formatMessage(labels.overview),
      icon: <Eye />,
      path: '',
    },
    {
      id: 'events',
      label: formatMessage(labels.events),
      icon: <Lightning />,
      path: '/events',
    },
    {
      id: 'sessions',
      label: formatMessage(labels.sessions),
      icon: <User />,
      path: '/sessions',
    },
    {
      id: 'realtime',
      label: formatMessage(labels.realtime),
      icon: <Clock />,
      path: '/realtime',
    },
    {
      id: 'reports',
      label: formatMessage(labels.reports),
      icon: <ChartPie />,
      path: '/reports',
    },
  ];

  const selectedKey = links.find(({ path }) => path && pathname.includes(path))?.id || 'overview';

  return (
    <Row marginBottom="6">
      <Tabs selectedKey={selectedKey}>
        <TabList>
          {links.map(({ id, label, icon, path }) => {
            return (
              <Tab key={id} id={id} href={renderUrl(`/websites/${website.id}${path}`)}>
                <Row alignItems="center" gap>
                  <Icon>{icon}</Icon>
                  <Text>{label}</Text>
                </Row>
              </Tab>
            );
          })}
        </TabList>
      </Tabs>
    </Row>
  );
}